/*
 * matrix_test.c
 *
 *  Created on: Nov 20, 2013
 *      Author: cinus
 */
#include <stdio.h>
#include <string.h>

#include "net.h"
#include "vectorizednet.h"
#include "jjann.h"
#include "types.h"
#include "training.h"

int main(int argc, char** argv) {
	unsigned int i, j;
	netdata_tp net;
	vectorizedNet_tp vnet;
	float32 *outputs;
	trainingData_t trainingData;
	float32 error, verror;

	//srand(SEED);

	net = initNetwork("configs/xor2.cfg");

	vnet = convertNet(net);

//	loadSamples(&trainingData, "datasets/xor.training");
	loadSamples(&trainingData, "datasets/iris.training");
	outputs = malloc(sizeof(float32)*trainingData.outputs);
//	printSamples(&trainingData);
	feedForwardV(vnet, trainingData.samples[0].input, outputs);
	fprintf(stderr, "V out: %f\n", outputs[0]);
	feedForward(net, trainingData.samples[0].input, outputs);
	fprintf(stderr, "S out: %f\n", outputs[0]);
	for (i = 0; i < 5; i++) {
//		fprintf(stderr, "+++++++++++++++++++++++++++++++++++++++++++++++\nBefore training %d\n", i);
//		printVecNet(vnet);
//		debugMatrix(net);
		verror = trainOneEpochV(vnet, &trainingData);
		error = trainOneEpoch(net, trainingData.samples, trainingData.sampleSize);
//		fprintf(stderr, "***********************************************After training %d\n", i);
//		printVecNet(vnet);
//		debugMatrix(net);
		fprintf(stderr, "std error: %f | vec error: %f\n", error, verror);
	}
//	fprintf(stderr, "std error: %f | vec error: %f\n", error, verror);
	//printVecNet(vnet);
	//debugMatrix(net);
	/*verror = validateV(vnet, trainingData.samples, trainingData.sampleSize);
	 error = validate(net, trainingData.samples, trainingData.sampleSize);
	 fprintf(stderr, "Validation\n------------------\nstd error: %f | vec error: %f\n", error, verror);
	 verror = validateV(vnet, trainingData.samples, trainingData.sampleSize);
	 error = validate(net, trainingData.samples, trainingData.sampleSize);
	 fprintf(stderr, "Validation\n------------------\nstd error: %f | vec error: %f\n", error, verror);
	 ovnet = (vectorizedNet_tp) malloc(sizeof(vectorizedNet_t));
	 reserveNetSpaceV(vnet, ovnet);
	 copyNetV(vnet, ovnet);
	 printVecNet(ovnet);
	 */
	free(outputs);
	destroyNetwork(net);
	destroyNetworkV(vnet);
	freeSamples(&trainingData);

	return 1;
}
